/************************************************************************
 * @file AbstractService.h
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#ifndef ABSTRACTSERVICE_H
#define ABSTRACTSERVICE_H

#include <map>
#include <memory>

#include <QString>
#include <QStringList>

#include <plugin/plugin_global.h>
#include <plugin/command/AbstractCommand.h>

using namespace std;

namespace antu
{
namespace plugin
{
// services are to be created by plugins and
// released by plugins.
class PLUGINSHARED_EXPORT AbstractService
{
public:
    AbstractService();

    AbstractService(const QString& serviceName)
        : m_sServiceName(serviceName)
    {
    }

    inline QString serviceName() const
    {
        return this->m_sServiceName;
    }

    bool registerCommand(AbstractCommandSharedPtr& command);

    AbstractCommand::CommandReturnType execute(const QString& commandName, const CommandParameters& inputs, CommandParameters& outputs);

    AbstractCommand::CommandReturnType execute(const QString& parameters, CommandParameters& outputs);

protected:
    QString m_sServiceName;
    CommandParameters m_oCommandContext;
    map<QString, AbstractCommandSharedPtr> m_oRegisteredCommands;

    AbstractCommandSharedPtr findCommand(const QString& commandName) const;
};

typedef shared_ptr<AbstractService> AbstractServiceSharedPtr;
}
}

#endif // ABSTRACTSERVICE_H
